$KCODE = 'u'

require 'rubygems'
require 'sinatra'
require 'erb'
# require 'activesupport'
require 'helpers'

require 'events_controller'
require 'user_controller'

# use Rack::Session::Pool, :key => 'rack.session', :path => '/', :expire_after => 3600

# ローカルテスト用の設定
configure :local do
  require 'logger'
  require 'dm-core'
  require 'dm-validations'
  # Configure DataMapper to use the local SQLite
  DataMapper.setup( :datastore, "sqlite3://#{Dir.pwd}/WEB-INF/appengine-generated/data_mapper.db" )
  require 'datamodels'
  require 'cruby/utils'
end

# GAEj環境用の設定
configure :production, :test, :development do
  require 'appengine-apis/logger'
  require 'dm-core'
  require 'dm-validations'
  require 'dm-aggregates'
  require 'dm-types'
  require 'dm-datastore-adapter/datastore-adapter'
  # Configure DataMapper to use the App Engine datastore
  # DataMapper.setup(:default, "appengine://auto")
  DataMapper.setup(:datastore, :adapter => :datastore, :database => 'sinatra')
  require 'datamodels'
  require 'gae/utils'
end



before do
  setup_logger
  # request.params.replace rails_like_params(params)
  @logger.debug request.inspect
  @logger.debug rails_like_request_start_log(request)
  @flash = {}
end


get '/login' do
  google_login_require '/events'
  redirect '/events'
end

get '/logout' do
  redirect google_logout('/')
end

get '/' do
  redirect 'index.html'
end

#error do
#  'エラーが発生しました。 - ' + env['sinatra.error'].name
#end
